package cn.iocoder.yudao.module.erp.dal.mysql.departquantity;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.erp.dal.dataobject.departquantity.DepartQuantityDO;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.erp.controller.admin.departquantity.vo.*;
import org.apache.ibatis.annotations.Select;

/**
 * 带量分配 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface DepartQuantityMapper extends BaseMapperX<DepartQuantityDO> {

    default PageResult<DepartQuantityDO> selectPage(DepartQuantityPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DepartQuantityDO>()
                .eqIfPresent(DepartQuantityDO::getProductId, reqVO.getProductId())
                .likeIfPresent(DepartQuantityDO::getProductName, reqVO.getProductName())
                .eqIfPresent(DepartQuantityDO::getBarCode, reqVO.getBarCode())
                .eqIfPresent(DepartQuantityDO::getCategoryId, reqVO.getCategoryId())
                .eqIfPresent(DepartQuantityDO::getUnitId, reqVO.getUnitId())
                .eqIfPresent(DepartQuantityDO::getStandard, reqVO.getStandard())
                .eqIfPresent(DepartQuantityDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(DepartQuantityDO::getCount, reqVO.getCount())
                .betweenIfPresent(DepartQuantityDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DepartQuantityDO::getId));
    }
    @Select("select id,name from system_dept  where status = 0 and deleted = 0 and parent_id = 100 and is_therapy_area = 1 order by  parent_id,sort")
    List<DeptDO> getDeptPage(DeptListReqVO pageReqVO);
    @Select("select dept_id,count from erp_depart_quantity where product_id = "+"#{id}")
    List<DepartQuantityRespVO> getQuantity(Long id);
    @Select(" select product_id from erp_depart_quantity where  product_id = #{productId}")
    List<String> selectForProduct(Long productId);
    @Delete(" delete from erp_depart_quantity where product_id = "+"#{productId}")
    void deleteForProduct(Long productId);
    @Select(" select edq.dept_id,edq.count from erp_depart_quantity edq left join  erp_product ep on edq.product_id = ep.id  where edq.product_id = #{id} ")
    List<DepartQuantityDO> seletDepartQuantity(Long id);
}